module.exports = function ($scope, $state, $resource, $modal, toaster ){
  $scope.searchform = {};
    //查询法律法规列表
    $scope.search = function (pageNo){
      
      
        var para = { 
            'name': $scope.searchform.name,
            'mobile' : $scope.searchform.mobile,
            'pageNo': pageNo || $scope.currentPage,
            'pageSize': $scope.itemsPerPage,
            'area_name2' : $scope.searchform.area_name2,
            'area_name3' : $scope.searchform.area_name3,
            'job_name' : $scope.searchform.job_name    
        }
        $resource('/api/as/ic/createcity/findUserList', {}, {}).save(para, function(res){
            if(res.errcode === 0){
                $scope.lists = res.data.results;
                $scope.totalItems = res.data.totalRecord;
                $scope.currentPage = pageNo;
                var map = {};
                var dest = [];
                var array = [];
                for(var i = 0; i < $scope.lists.length; i++){
                  var ai = $scope.lists[i];
                  if(!map[ai.area_name1]){
                      dest.push({
                        area_name1: ai.area_name1,
                          data: [ai]
                      });
                      map[ai.area_name1] = ai;
                  }else{
                      for(var j = 0; j < dest.length; j++){
                          var dj = dest[j];
                          if(dj.area_name1 == ai.area_name1){
                              dj.data.push(ai);
                              break;
                          }
                      }
                  }
                }
                console.log('重组数组');
                $scope.list = dest;
                console.log($scope.list);
              
            }else{
                toaster.error({title: '', body: res.errmsg});
            }
        });
    }
    


    init();
    //初始化列表
    function init(){
        $scope.currentPage = 1;		//当前页码
        $scope.itemsPerPage = 10;	//每页显示几条
        $scope.search(1);
    }


        //查看
        $scope.gatLawinfo = function(aa) {
            var modalInstance = $modal.open({
                template: require('../views/userinfo.html'),
                controller: 'userinfo',
                size: 'lg',
                resolve: {
                    item : function () {
                        return aa;
                    },
                    flag : function () {
                        return aa == 1;
                    }
                }
            });
            //关闭模态框刷新页面
            modalInstance.result.then(function() {
                init();
            });
        }

        $scope.del = function (info){
            var para = {
                'id': info.id
            }
            $resource('/api/as/ic/createcity/delUser', {}, {}).save(para, function(res){
                if(res.errcode === 0){
                    init();
                    toaster.success({title: '', body: '删除成功'});
                }else{
                    toaster.error({title: '', body: res.errmsg});
                }
            });
        }


};